package com.umfwechat.lightprogram.controller.selfdeploy;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.umfwechat.common.constant.CacheConsts;
import com.umfwechat.common.constant.CommonConsts;
import com.umfwechat.common.constant.ValueConsts;
import com.umfwechat.util.DesIDUtil;
import com.umfwechat.util.HttpUtil;
import com.umfwechat.util.MessageDigestUtil;
import com.umfwechat.util.PropertyUtil;
import com.umfwechat.util.RedisUtil;
import com.umfwechat.util.ReqMessageUtil;
import com.umfwechat.util.SaasPropertyUtil;
import com.umfwechat.util.StringUtil;
import com.umpay.operation.common.RetCode;
import com.umpay.operation.model.merInfo.MerInfo;
import com.umpay.operation.model.merInfo.MerInfoEx;
import com.umpay.operation.model.product.MerProduct;
import com.umpay.operation.model.spapplyplat.JoinFlow;
import com.umpay.operation.service.merInfo.remote.MerInfoServiceRemote;
import com.umpay.operation.service.product.MerProductServiceRemote;
import com.umpay.operation.service.spapplyplat.remote.JoinFlowServiceRemote;
import com.umpay.sp.model.common.ReqMessage;
import com.umpay.sp.model.common.ResMessage;
import com.umpay.sp.model.saas.StoreInf;

import com.umpay.sp.service.saas.remote.StoreInfServiceRemote;
import com.umpay.sp.util.SerialUtil;

/**
 * 自助部署列表、部署详情、修改店铺详情 ,删除Controller
 * @author ChenFuLong 2017-05-16
 * @version V1.0
 */
@Controller
@RequestMapping("/merchantDeploy")
public class MerchantController {

	private static Logger logger = LoggerFactory.getLogger(MerchantJoinController.class);
	
	@Resource
	private StoreInfServiceRemote storeInfServiceRemote;  
	
	@Resource
	private JoinFlowServiceRemote joinFlowServiceRemote;
	@Resource
	private MerInfoServiceRemote merInfoService;
	@Resource
	private MerProductServiceRemote merProductServiceRemote;
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + 自助部署列表 + + + + + + + + + + + + + + + + + + + + + + + + + + + */
	
	/**
	 * 自助部署列表
	 * @author ChenFuLong 2017-05-16
	 * @param session
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/merchantList", produces="application/json;charset=UTF-8")
	@ResponseBody
	@SuppressWarnings("unchecked")
	public JSONObject merchantList(HttpSession session,HttpServletRequest request, HttpServletResponse response) throws Exception{
		logger.info("----#---------#--获取自助部署列表，开始--#---------#--");
		JSONObject resultJson = new JSONObject();
		String reqJSON = (String) request.getAttribute("_requestData");
		JSONObject json = null;
		try {
			json = JSONObject.fromObject(reqJSON);
		} catch (Exception e) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "请求参数不足");
			logger.error("----#---------#--请求自助部署列表数据转换异常--#---------#--" + e);
			return resultJson;
		}
		//判断自助部署查询立码付还是POS机   0：立码付   1：POS机
		String productId = (String) json.get("productId");
		if(StringUtil.isEmpty(productId)){
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "请求参数不足（请求类别pos或者立码付）");
			logger.info("请求参数不足！");
			return resultJson;
		}
		logger.info("自助部署查询的请求类别为：" + productId);
		String agentId = (String) json.get("loginAgentId");	//代理商编号
		String salesmanId = (String) json.get("loginUserId");	//业务员编号 
		String pageNo = (String) json.get("pageNo");	//当前页
		String type = (String) json.get("type");	//入网类型
		if(StringUtil.isEmpty(pageNo)){
			pageNo="1";
		}
		String pageSize = (String) json.get("pageSize");	//每页条数
		if(StringUtil.isEmpty(pageSize)){
			pageSize="20";
		}
		Integer startNo = Integer.valueOf(pageSize)*(Integer.valueOf(pageNo)-1);	//计算开始行数
		Integer endNo = Integer.valueOf(pageSize)*Integer.valueOf(pageNo);	//计算结束行数
		String posState = (String) json.get("posState"); 
		//查询POS机自助部署列表
		if("1".equals(StringUtil.trim(productId))){
			resultJson = queryPosList(agentId,salesmanId,posState,pageSize,pageNo);
			return resultJson;
		}
		ReqMessage req = ReqMessageUtil.makeSpReq();
		ResMessage res = null;
		req.put("agentId",agentId);
		if (!"admin".equals(salesmanId)) {	//业务员只能看自己的，代理商可以看全部
			req.put("salesmanId",salesmanId);
		}
		if("0".equals(type)){
			req.put("type",type);
		}else if("1".equals(type)){
			req.put("type",type);
		}
		req.put("startNo",startNo.toString());
		req.put("endNo",endNo.toString());
		//立马付状态：02待提交店铺；03待上传照片；04待开通产品；05待邀请商户；10待商户签约；06-待修改；
		//POS状态：50-一级代理商审核；51-二级代理商审核；53-三级代理商审核；54-风险审核；55-财务审核；56-运营报备；57-运营开启；58-运营提现配置；59-运营终端分拔；61-运营手续费配置
		req.put("registerProcsStates","'02','03','04','05','06','10','50','51','53','54','55','56','57','58','59','61'");
		try {
			logger.info("----#---------#--获取自助部署列表，请求参数：--#---------#--" + req);
			res = storeInfServiceRemote.getStoreInfList(req);
			logger.info("----#---------#--获取自助部署列表，返回参数：--#---------#--" + res);
		} catch (Exception e) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "服务器异常，请稍后再试");
			logger.error("----#---------#--获取自助部署列表异常--#---------#--" + e);
			return resultJson;
		}
		if ("0000".equals(res.getRetCode())) {
			List<StoreInf> storeInfs = (List<StoreInf>) res.getResMap().get("storeInfList");
			List<Map<String, String>> list = new ArrayList<Map<String, String>>();
			for (int i = 0; i < storeInfs.size(); i++) {
				Map<String, String> map = new HashMap<String, String>();
				if(StringUtil.isEmpty(storeInfs.get(i).getStoreShortName())){
					map.put("storeShortName", "名称待填写");
				}else {
					map.put("storeShortName", storeInfs.get(i).getStoreShortName());
				}
				map.put("payeeName", storeInfs.get(i).getPayeeName());
				map.put("payeeMobile", storeInfs.get(i).getPayeeMobileId());
				map.put("state", storeInfs.get(i).getRegisterProcsState());
				map.put("storeId", storeInfs.get(i).getStoreId());
				map.put("type", storeInfs.get(i).getType());
				list.add(map);
			}
			resultJson.put("storeList", list);
			resultJson.put("retCode", "0000");
			resultJson.put("retMsg", "成功");
		}else {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "获取自助部署列表失败");
		}
		return resultJson;
	}
	
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + 店铺部署详情（展示当前店铺的详细信息） + + + + + + + + + + + + + + + + + + + + + + + + + + + */
	
	/**
	 * 店铺部署详情
	 * @author ChenFuLong 2017-05-19
	 * @param session
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@RequestMapping(value="/merchantDetail", produces="application/json;charset=UTF-8")
	@ResponseBody
	public JSONObject merchantDetail(HttpSession session,HttpServletRequest request, HttpServletResponse response) throws Exception{
		logger.info("----#---------#--获取店铺部署详情，开始--#---------#--");
		JSONObject resultJson = new JSONObject();
		String reqJSON = (String) request.getAttribute("_requestData");
		JSONObject json = null;
		try {
			json = JSONObject.fromObject(reqJSON);
		} catch (Exception e) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "请求参数不足");
			logger.error("----#---------#--请求自助部署列表数据转换异常--#---------#--" + e);
			return resultJson;
		}
		String storeId = (String) json.get("storeId");	//店铺编号
		if (StringUtil.isEmpty(storeId)) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "请求参数不足");
			logger.info("----#---------#--获取店铺部署详情，请求参数不足--#---------#--");
			return resultJson;
		}
		/**
		 * 获取店铺部署详情
		 */
		ReqMessage reqStoreInf = ReqMessageUtil.makeSpReq();
		ResMessage resStoreInf = null;
		reqStoreInf.put("storeId",storeId);	//店铺编号
		try {
			logger.info("----#---------#--获取店铺部署详情，请求参数：--#---------#--" + reqStoreInf);
			resStoreInf = storeInfServiceRemote.getStoreInfByPri(reqStoreInf);
			logger.info("----#---------#--获取店铺部署详情，返回参数：--#---------#--" + resStoreInf);
		} catch (Exception e) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "服务器异常，请稍后再试");
			logger.error("----#---------#--获取店铺部署详情异常--#---------#--" + e);
			return resultJson;
		}
		if(!"0000".equals(resStoreInf.getRetCode())){	//查询店铺详情失败或异常
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "服务器异常，请稍后再试");
			return resultJson;
		}else if(resStoreInf.getResMap().get("storeInf") == null){	//未获取到店铺信息，storeId不存在
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "获取店铺信息失败");
			return resultJson;
		}
		
		StoreInf storeInf = (StoreInf) resStoreInf.getResMap().get("storeInf");
		
		/**
		 * 获取驳回信息
		 */
		resultJson.put("opinion", "");	//审核意见
		com.umpay.operation.common.ReqMessage reqMerNoPassInf = ReqMessageUtil.makeOpReq();
		com.umpay.operation.common.ResMessage resMerNoPassInf = null;
		
		//reqMerNoPassInf.put("merId",storeInf.getStoreId());	//商户号
		reqMerNoPassInf.put(CommonConsts.MERUNIFORMID,storeInf.getStoreId());	//商户唯一标识
		reqMerNoPassInf.put("handleRole","02");	//处理人角色：00系统自动；01财务； 02运营； 03客服 ；04商户 ；99其他
		try {
			logger.info("----#---------#--获取店铺驳回信息，请求参数：--#---------#--" + reqMerNoPassInf);
			resMerNoPassInf = joinFlowServiceRemote.queryJoinFlowList(reqMerNoPassInf);
			logger.info("----#---------#--获取店铺驳回信息，返回参数：--#---------#--" + resMerNoPassInf);
		} catch (Exception e) {
			resultJson.put("opinion", "");	//审核意见
			logger.error("----#---------#--获取店铺驳回信息异常--#---------#--" + e);
		}
		if("0000".equals(resMerNoPassInf.getRetCode())){
			List<JoinFlow> joinFlows = (List<JoinFlow>) resMerNoPassInf.getResMap().get("joinFlowList");
			if(joinFlows.size() > 0){
				ListSort(joinFlows); //排序后取最新
				resultJson.put("opinion", joinFlows.get(joinFlows.size() - 1).getRemark());	//审核意见
			}else {
				resultJson.put("opinion", "");	//审核意见
			}
		}else {
			resultJson.put("opinion", "");	//审核意见
			logger.info("----#---------#--获取店铺驳回信息异常--#---------#--");
		}
		
		/**
		 * 获取店铺列表，判断手机是否可以修改（开通产品信息和收款人手机号在签约以后不可以修改）
		 */
		resultJson.put("canMobileModify", "0");	//手机号是否可以修改：0可以；1不可以
		ReqMessage reqStoreList = ReqMessageUtil.makeSpReq();
		ResMessage resStoreList = null;
		reqStoreList.put("merId",storeInf.getMerId());
		reqStoreList.put("registerProcsStates","'06','09','07','08'");
		try {
			logger.info("----#---------#--获取自助部署列表，请求参数：--#---------#--" + reqStoreList);
			resStoreList = storeInfServiceRemote.getStoreInfList(reqStoreList);
			logger.info("----#---------#--获取自助部署列表，返回参数：--#---------#--" + resStoreList);
		} catch (Exception e) {
			resultJson.put("canMobileModify", "1");	//手机号是否可以修改：0可以；1不可以
			logger.error("----#---------#--获取自助部署列表异常--#---------#--" + e);
		}
		Integer totalSize = (Integer) resStoreList.getResMap().get("totalSize");
		if (resStoreList.getRetCode().equals("0000") && totalSize > 0) {
			resultJson.put("canMobileModify", "1");	//手机号是否可以修改：0可以；1不可以
		}
		String imgHttpUrl = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties","img.http.url", "");	//获取图片服务器Http地址
		String imgFileUrl = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties","saasPlat.comp.uploadPath", "");	//获取图片服务器存储地址
		logger.info("----#---------#--获取umfWeChatPlat_appConf.properties配置文件中的参数--#---------#--" + imgHttpUrl + imgFileUrl);
		resultJson.put("retCode", "0000");	//
		resultJson.put("retMsg", "成功");	//
		resultJson.put("storeId", storeInf.getStoreId());	//商户编号
		resultJson.put("storeShortName", storeInf.getStoreShortName());	//商家简称
		resultJson.put("storeCategory", (storeInf.getStoreCategory()).replace("&", ","));	//商户类别
		resultJson.put("storeAddress", storeInf.getStoreAddrProv() + "," + storeInf.getStoreAddrCity() + "," + storeInf.getStoreAddrArea());	//商户地址：省市区
		resultJson.put("storeFullAddress", storeInf.getStoreFullAddr());	//详细地址
		resultJson.put("payeeName", storeInf.getPayeeName());	//收款人姓名
		resultJson.put("payeeMobile", storeInf.getPayeeMobileId());	//收款人手机
		resultJson.put("payeeIdentity", DesIDUtil.desID2Star(storeInf.getPayeeInidcard()));	//收款人身份证号码
		resultJson.put("payeeInidcardValid", storeInf.getPayeeInidcardValid());	//证件有效期
		resultJson.put("storeType", storeInf.getStoreType());	//商户类型
		resultJson.put("licenseNo", storeInf.getLicenseNo());	//营业执照号
		resultJson.put("storeName", storeInf.getStoreFullName());	//商户全称
		resultJson.put("storeMan", storeInf.getCategoryManName());	//经营者姓名
		resultJson.put("storeManIdentity", DesIDUtil.desID2Star(storeInf.getCategoryManCardno()));	//经营者身份证号码
		resultJson.put("storeManIdentityValid", storeInf.getCategoryInidcardValid());	//证件有效期
		resultJson.put("registerDate", storeInf.getRegisterDate());	//注册日期
		resultJson.put("storeKind", storeInf.getMainBusiness());	//主营业务
		resultJson.put("registerAddress", storeInf.getRgstaddress());	//注册地址
		resultJson.put("payeeCardPhotoFrontUrl", storeInf.getPayeeCardPhotoFront().equals("") ? storeInf.getPayeeCardPhotoFront() : imgHttpUrl + imgFileUrl + storeInf.getStoreId() + "/" + storeInf.getPayeeCardPhotoFront());	//收款人身份证正面
		resultJson.put("payeeCardPhotoConUrl", storeInf.getPayeeCardPhotoCon().equals("") ? storeInf.getPayeeCardPhotoCon() : imgHttpUrl + imgFileUrl + storeInf.getStoreId() + "/" + storeInf.getPayeeCardPhotoCon());	//收款人身份证反面
		resultJson.put("categoryCardPhotoFrontUrl", storeInf.getCategoryCardPhotoFront().equals("") ? storeInf.getCategoryCardPhotoFront() : imgHttpUrl + imgFileUrl + storeInf.getStoreId() + "/" + storeInf.getCategoryCardPhotoFront());	//经营者身份证正面
		resultJson.put("categoryCardPhotoCon", storeInf.getCategoryCardPhotoCon().equals("") ? storeInf.getCategoryCardPhotoCon() : imgHttpUrl + imgFileUrl + storeInf.getStoreId() + "/" + storeInf.getCategoryCardPhotoCon());	//经营者身份证反面
		resultJson.put("shopSignFrontUrl", storeInf.getShopSignPhotoFront().equals("") ? storeInf.getShopSignPhotoFront() : imgHttpUrl + imgFileUrl + storeInf.getStoreId() + "/" + storeInf.getShopSignPhotoFront());	//店铺招牌图片地址
		resultJson.put("shopInUrl", storeInf.getShopSignPhotoCon().equals("") ? storeInf.getShopSignPhotoCon() : imgHttpUrl + imgFileUrl + storeInf.getStoreId() + "/" + storeInf.getShopSignPhotoCon());	//店铺内景图片地址
		resultJson.put("storeLicenseNoUrl", storeInf.getBusiLicensePhoto().equals("") ? storeInf.getBusiLicensePhoto() : imgHttpUrl + imgFileUrl + storeInf.getStoreId() + "/" + storeInf.getBusiLicensePhoto());	//营业执照图片地址
		resultJson.put("authCertUrl", storeInf.getAuthCertPhoto().equals("") ? storeInf.getAuthCertPhoto() : imgHttpUrl + imgFileUrl + storeInf.getStoreId() + "/" + storeInf.getAuthCertPhoto());	//授权函图片地址
		resultJson.put("state", storeInf.getRegisterProcsState());	//处理状态
		resultJson.put("labelOne", storeInf.getLabelOne());//label_one
		resultJson.put("labelTwo", storeInf.getLabelTwo());//label_two
		resultJson.put("salesmanId", storeInf.getSalesmanId());//业务员编号
		resultJson.put("email", storeInf.getEmail());//邮箱
		resultJson.put("type", storeInf.getType());//入网类型
		resultJson.put("isPos", storeInf.getIsOpenPos());//是否要开pos
		//resultJson.put("phone", storeInf.getPhone());//客服电话
		if (DesIDUtil.decID(storeInf.getPayeeInidcard()).equals(DesIDUtil.decID(storeInf.getCategoryManCardno()))) {
			resultJson.put("isAuthorize", "0");
		}else {
			resultJson.put("isAuthorize", "1");
		}
		return resultJson;
	}
	
	/**
	 * 对返回的驳回信息进行排序
	 * @param list
	 */
	private static void ListSort(List<JoinFlow> list) {
		Collections.sort(list, new Comparator<JoinFlow>() {
			@Override
			public int compare(JoinFlow o1, JoinFlow o2) {
				SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
				try {
					Date dt1 = format.parse(o1.getIntime());
					Date dt2 = format.parse(o2.getIntime());
					if (dt1.getTime() > dt2.getTime()) {
						return 1;
					} else if (dt1.getTime() < dt2.getTime()) {
						return -1;
					} else {
						return 0;
					}
				} catch (Exception e) {
					e.printStackTrace();
				}
				return 0;
			}
		});
	}
	
	
/* + + + + + + + + + + + + + + + + + + + + + + + + + + + 修改店铺详情 + + + + + + + + + + + + + + + + + + + + + + + + + + + */	
	
	
	/**
	 * 修改店铺详情（店铺部署详情页面提交修改按钮）
	 * @param session
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/merchantModify", produces="application/json;charset=UTF-8")
	@ResponseBody
	@SuppressWarnings("unchecked")
	public JSONObject merchantModify(HttpSession session,HttpServletRequest request, HttpServletResponse response) throws Exception{
		logger.info("----#---------#--获取店铺部署详情，开始--#---------#--");
		JSONObject resultJson = new JSONObject();
		String reqJSON = (String) request.getAttribute("_requestData");
		JSONObject json = null;
		try {
			json = JSONObject.fromObject(reqJSON);
		} catch (Exception e) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "请求参数不足");
			logger.error("----#---------#--请求自助部署列表数据转换异常--#---------#--" + e);
			return resultJson;
		}
		String storeId = (String) json.get("storeId");	//店铺编号
		String state = (String) json.get("state");	//店铺状态
		String payeeMobile = (String) json.get("payeeMobile");	//收款人手机
		String storeShortName = (String) json.get("storeShortName");	//商家简称
		
		String storeCategory = (String) json.get("storeCategory");	//商户类别
		if (StringUtil.isNotEmpty(storeCategory)) {
			storeCategory = storeCategory.replace(",", "&");
		}
		String address = (String) json.get("storeAddress");	//商户地址：省，市，区
		//String storeAddress[] = ((String) json.get("storeAddress")).split(",");	//商户地址：省，市，区
		String storeFullAddress = (String) json.get("storeFullAddress");	//详细地址
		String payeeInidcardValid = (String) json.get("payeeInidcardValid");	//证件有效期
		String storeType = (String) json.get("storeType");	//商户类型
		String licenseNo = (String) json.get("licenseNo");	//营业执照号
		String storeName = (String) json.get("storeName");	//商户全称
		String storeMan = (String) json.get("storeMan");	//经营者姓名
		String storeManIdentity = (String) json.get("storeManIdentity");	//经营者身份证号码
		String storeManIdentityValid = (String) json.get("storeManIdentityValid");	//证件有效期
		String registerDate = (String) json.get("registerDate");	//注册日期
		String storeKind = (String) json.get("storeKind");	//主营业务
		String registerAddress = (String) json.get("registerAddress");	//注册地址
		String labelOne=(String) json.get("labelOne");
		String labelTwo=(String) json.get("labelTwo");
		String email=(String) json.get("email");//商户邮箱-3期
		String phone = (String) json.get("phone");	//客服电话-3期
		String formId = (String) json.get("formId");	//表单编号
		String loginUserId = (String) json.get("loginUserId");	//登陆的用户名
		if (StringUtil.isEmpty(storeId) || StringUtil.isEmpty(state)) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "请求参数不足");
			logger.info("----#---------#--修改店铺详情，请求参数不足--#---------#--");
			return resultJson;
		}
		/**
		 * 获取店铺部署详情
		 */
		ReqMessage reqStoreInf = ReqMessageUtil.makeSpReq();
		ResMessage resStoreInf = null;
		reqStoreInf.put("storeId",storeId);	//店铺编号
		try {
			logger.info("----#---------#--获取店铺部署详情，请求参数：--#---------#--" + reqStoreInf);
			resStoreInf = storeInfServiceRemote.getStoreInfByPri(reqStoreInf);
			logger.info("----#---------#--获取店铺部署详情，返回参数：--#---------#--" + resStoreInf);
		} catch (Exception e) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "服务器异常，请稍后再试");
			logger.error("----#---------#--获取店铺部署详情异常--#---------#--" + e);
			return resultJson;
		}
		if(!"0000".equals(resStoreInf.getRetCode())){	//查询店铺详情失败或异常
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "服务器异常，请稍后再试");
			return resultJson;
		}else if(resStoreInf.getResMap().get("storeInf") == null){	//未获取到店铺信息，storeId不存在
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "获取店铺信息失败");
			return resultJson;
		}
		
		StoreInf storeInf = (StoreInf) resStoreInf.getResMap().get("storeInf");
		
		if(storeInf.getRegisterProcsState().equals("08")){	//运营审核通过以后不允许业务员修改任何信息，需联系客服运营人员修改控制风险。
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "审核通过的店铺禁止修改，如需修改请联系客服");
			return resultJson;
		}
		
		if(null !=  payeeMobile && !payeeMobile.equals(storeInf.getPayeeMobileId())){	//如果用户修改了手机号
			/**
			 * 获取店铺列表，判断手机是否可以修改（开通产品信息和收款人手机号在签约以后不可以修改）
			 */
			ReqMessage reqStoreList = ReqMessageUtil.makeSpReq();
			ResMessage resStoreList = null;
			reqStoreList.put("merId",storeInf.getMerId());
			try {
				logger.info("----#---------#--获取自助部署列表，请求参数：--#---------#--" + reqStoreList);
				resStoreList = storeInfServiceRemote.getStoreInfList(reqStoreList);
				logger.info("----#---------#--获取自助部署列表，返回参数：--#---------#--" + resStoreList);
			} catch (Exception e) {
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "服务器异常，请稍后再试");
				logger.error("----#---------#--获取自助部署列表异常--#---------#--" + e);
				return resultJson;
			}
			if (!"0000".equals(resStoreList.getRetCode())) {
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "服务器异常，请稍后再试");
				return resultJson;
			}
			Integer totalSize = (Integer) resStoreList.getResMap().get("totalSize");
			List<StoreInf> storeInfs = (List<StoreInf>) resStoreList.getResMap().get("storeInfList");
			if (totalSize > 1) {	//大于1，说明有其它子店铺
				for (int i = 0; i < storeInfs.size(); i++) {	//不能修改手机号
					if (storeInfs.get(i).getRegisterProcsState().equals("06")
							|| storeInfs.get(i).getRegisterProcsState().equals("07")
							|| storeInfs.get(i).getRegisterProcsState().equals("08")
							|| storeInfs.get(i).getRegisterProcsState().equals("09")) {
						resultJson.put("retCode", "0001");
						resultJson.put("retMsg", "手机号不可以修改");
						return resultJson;
					}
				}
				/**
				 * 修改所有子店铺手机号
				 */
				ReqMessage req = ReqMessageUtil.makeSpReq();
				ResMessage res = null;
				req.put("merId",storeInf.getMerId());	//主商户号
				req.put("payeeMobileId",payeeMobile);	//手机号
				try {
					logger.info("----#---------#--根据主商户号修改所有子商户手机号码，请求参数--#---------#--" + req);
					res = storeInfServiceRemote.updateStoreByMerIdOrStoreId(req);
					logger.info("----#---------#--根据主商户号修改所有子商户手机号码，返回参数--#---------#--" + res);
				} catch (Exception e) {
					resultJson.put("retCode", "0001");
					resultJson.put("retMsg", "服务器异常，请稍后再试");
					logger.error("----#---------#--根据主商户号修改所有子商户手机号码异常--#---------#--" + e);
					return resultJson;
				}
				if(!"0000".equals(res.getRetCode())){
					resultJson.put("retCode", "0001");
					resultJson.put("retMsg", "服务器异常，请稍后再试");
					return resultJson;
				}
				
			}
			/**
			 * 修改主商户手机号
			 */
			ReqMessage reqMer = ReqMessageUtil.makeSpReq();
			ResMessage resMer = null;
			reqMer.put("storeId",storeInf.getMerId()); //主商户编号，即主商户ID
			reqMer.put("payeeMobileId",payeeMobile);	//手机号
			try {
				logger.info("----#---------#--修改主商户手机号，请求参数：--#---------#--" + reqMer);
				resMer = storeInfServiceRemote.updateStoreByMerIdOrStoreId(reqMer);
				logger.info("----#---------#--修改主商户手机号，返回参数：--#---------#--" + resMer);
			} catch (Exception e) {
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "服务器异常，请稍后再试");
				logger.error("----#---------#--修改主商户手机号异常--#---------#--" + e);
				return resultJson;
			}
		}
		
		if (null != storeShortName && !storeShortName.equals(storeInf.getStoreShortName())) {	//如果用户修改了店铺简称
			/**
			 * 根据主商户号和商户简称查询是否已存在
			 */
			ReqMessage reqCountStore = ReqMessageUtil.makeSpReq();
			ResMessage resCountStore = null;
			reqCountStore.put("storeShortName",storeShortName);	//商户简称
			reqCountStore.put("merId",storeInf.getMerId());	//主商户号
			try {
				logger.info("----#---------#--根据主商户号和商户简称查询是否已存在，请求参数：--#---------#--" + reqCountStore);
				resCountStore = storeInfServiceRemote.countStoreInfByStoreNameAndMerId(reqCountStore);
				logger.info("----#---------#--根据主商户号和商户简称查询是否已存在，返回参数：--#---------#--" + resCountStore);
			} catch (Exception e) {
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "服务器异常，请稍后再试");
				logger.error("----#---------#--根据主商户号和商户简称查询是否已存在异常--#---------#--" + e);
				return resultJson;
			}
			if ("0000".equals(resCountStore.getRetCode())) {
				Integer storeCount = (Integer) resCountStore.getResMap().get("storeCount");
				if (storeCount > 0) {
					resultJson.put("retCode", "0001");
					resultJson.put("retMsg", "商户简称已存在");
					return resultJson;
				}
			}else {
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "服务器异常，请稍后再试");
				return resultJson;
			}
		}
		
		if (!payeeInidcardValid.equals(storeInf.getPayeeInidcardValid())) {	//如果用户修改了证件有效期
			/**
			 * 修改所有子商户证件有效期
			 */
			ReqMessage req = ReqMessageUtil.makeSpReq();
			ResMessage res = null;
			req.put("merId",storeInf.getMerId());	//主商户号
			req.put("payeeInidcardValid",payeeInidcardValid);	//证件有效期
			try {
				logger.info("----#---------#--根据主商户号修改所有子商户证件有效期，请求参数--#---------#--" + req);
				res = storeInfServiceRemote.updateInidcardValidByMerIdOrStoreId(req);
				logger.info("----#---------#--根据主商户号修改所有子商户证件有效期，返回参数--#---------#--" + res);
			} catch (Exception e) {
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "服务器异常，请稍后再试");
				logger.error("----#---------#--根据主商户号修改所有子商户证件有效期异常--#---------#--" + e);
				return resultJson;
			}
			if(!"0000".equals(res.getRetCode())){
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "服务器异常，请稍后再试");
				return resultJson;
			}
			
			/**
			 * 修改主商户证件有效期
			 */
			ReqMessage reqMer = ReqMessageUtil.makeSpReq();
			ResMessage resMer = null;
			reqMer.put("storeId",storeInf.getMerId()); //主商户编号，即主商户ID
			reqMer.put("payeeInidcardValid",payeeInidcardValid);	//证件有效期
			try {
				logger.info("----#---------#--修改主商户证件有效期，请求参数：--#---------#--" + reqMer);
				resMer = storeInfServiceRemote.updateInidcardValidByMerIdOrStoreId(reqMer);
				logger.info("----#---------#--修改主商户证件有效期，返回参数：--#---------#--" + resMer);
			} catch (Exception e) {
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "服务器异常，请稍后再试");
				logger.error("----#---------#--修改主商户证件有效期异常--#---------#--" + e);
				return resultJson;
			}
		}
		
		/**
		 * 更新当前店铺信息
		 */
		if (payeeMobile != null) {
			storeInf.setPayeeMobileId(payeeMobile);
		}else {
			storeInf.setPayeeMobileId(storeInf.getPayeeMobileId());
		}
		if (storeInf.getRegisterProcsState().equals("06")) {	//如果店铺状态为‘待修改’，则变更为‘待复查’
			storeInf.setRegisterProcsState("09");	//待复查
			logger.info("变更为‘待复查’插入操作记录 ------");	
			addJoinFlowForCheckMer(storeInf);
		}
		storeInf.setStoreShortName(storeShortName);	//商家简称
		storeInf.setStoreCategory(storeCategory);	//商户类别
		if (StringUtil.isNotEmpty(address)) {
			String storeAddress[] = ((String) json.get("storeAddress")).split(",");
			storeInf.setStoreAddrProv(storeAddress[0]);	//商户地址：省
			storeInf.setStoreAddrCity(storeAddress[1]);	//商户地址：市
			//修复bug 东莞下没区
			if(storeAddress.length == 3){
				storeInf.setStoreAddrArea(storeAddress[2]);	//商户地址：区	
			}
		}
		storeInf.setStoreFullAddr(storeFullAddress);	//详细地址
		storeInf.setPayeeInidcardValid(payeeInidcardValid);	//证件有效期
		storeInf.setStoreType(storeType);	//商户类型
		storeInf.setLicenseNo(licenseNo);	//营业执照号
		storeInf.setStoreFullName(storeName);	//商户全称
		storeInf.setCategoryManName(storeMan);	//经营者姓名
		if (StringUtil.isNotEmpty(storeManIdentity) && !storeManIdentity.contains("*")) {
			storeInf.setCategoryManCardno(DesIDUtil.encID(storeManIdentity));	//经营者身份证号码
		}
		storeInf.setCategoryInidcardValid(storeManIdentityValid);	//证件有效期
		storeInf.setRegisterDate(registerDate);	//注册日期
		storeInf.setMainBusiness(storeKind);	//主营业务
		storeInf.setRgstaddress(registerAddress);	//注册地址
		storeInf.setLabelOne(labelOne);
		storeInf.setLabelTwo(labelTwo);
		storeInf.setEmail(email);
		storeInf.setPhone(phone);
		storeInf.setIntime(null);
		storeInf.setModtime(null);
		storeInf.setFormId(formId);//表单编号
		storeInf.setLastModuser(loginUserId);
		Map<String, String> storeMap = SaasPropertyUtil.javaBeanToMap(storeInf);
		ReqMessage req = ReqMessageUtil.makeSpReq();
		ResMessage res = null;
		req.putAll(storeMap);
		try {
			logger.info("----#---------#--更新店铺信息，请求参数：--#---------#--" + req);
			res = storeInfServiceRemote.updateStoreInf(req);
			logger.info("----#---------#--更新店铺信息，返回参数：--#---------#--" + res);
		} catch (Exception e) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "服务器异常，请稍后再试");
			logger.error("----#---------#--更新店铺信息异常--#---------#--" + e);
			return resultJson;
		}
		if(!"0000".equals(res.getRetCode())){
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "修改失败");
			return resultJson;
		}
		//更新当期店铺的merinf表信息
		if (!"03".equals(state) && !"02".equals(state)) {	
			//如果店铺状态不为待提交店铺信息02，不为待上传照片02，说明商户表已经有数据，就更新T_MER_INF表
			com.umpay.operation.common.ReqMessage reqU = ReqMessageUtil.makeOpReq();
			MerInfo merInfo = new MerInfo();
			MerInfoEx merInfoEx = new MerInfoEx();
			//商户编号
			merInfoEx.setMerId(storeInf.getStoreId());	//0商户编号
			merInfo.setMerId(storeInf.getStoreId());	//0商户编号
			//商户简称
			merInfo.setMerName(storeInf.getStoreShortName());	//1如果是店铺则传商户名称
			//收款人姓名
			merInfoEx.setLinkName(storeInf.getPayeeName());	//联系人姓名
			//收款人手机号
			merInfoEx.setTelephone(storeInf.getPayeeMobileId());	//手机
			//商户地址
			if (StringUtil.isNotEmpty(address)) {
				String storeAddress[] = ((String) json.get("storeAddress")).split(",");
				merInfoEx.setProvince(storeAddress[0]);//省
				merInfoEx.setArea(storeAddress[1]);//市
			}
			//详细地址
			merInfo.setAddress(storeInf.getStoreFullAddr());	//8地址
			//客服电话
			merInfo.setCusPhone(phone);	//6客服电话
			//商户邮箱
			merInfoEx.setEmail(email);
			merInfoEx.setRegCapital(0);
			if (StringUtil.isNotEmpty(storeInf.getMerId())) {
				String[] industrys = storeInf.getStoreCategory().split("&");
				merInfoEx.setIndustryTypeId(industrys[0]);	//行业大类(一级)
				merInfoEx.setIndustryIdSecond(industrys[1]);	//行业(二级)
				if (industrys.length >2) {
					merInfoEx.setIndustrySonTypeId(industrys[2]);	//行业子类V(三级)
				}
			}
			//商户类型，小微。个体
			String type = storeInf.getStoreType();
			if("1".equals(type)){
				//营业执照号
				merInfoEx.setLicenseNo(storeInf.getLicenseNo());	//1营业执照编号
				//商户全称
				merInfoEx.setCorpName(storeInf.getStoreFullName());	//2企业名称
				//注册地址
				merInfoEx.setRgstAddress(storeInf.getRgstaddress());	//8注册地址
				//经营者姓名
				merInfoEx.setLawyer(storeInf.getCategoryManName());	//3法人
				//身份证号码
				merInfoEx.setCertCode(DesIDUtil.decID(storeInf.getCategoryManCardno()));	//4法人身份证
			}
			merInfo.setExMerId(storeInf.getMerId());
			Map<String, Object> merInfMap = new HashMap<>();
			Map<String, Object> merInfoExMap =  new HashMap<>();
			try {
				merInfMap = SaasPropertyUtil.javaBeanToMapO((merInfo));
				merInfoExMap = SaasPropertyUtil.javaBeanToMapO(merInfoEx);
			} catch (Exception e1) {
				logger.error("商户对象信息转map失败",e1);
			}
			reqU.putAll(merInfMap);
			reqU.putAll(merInfoExMap);
			com.umpay.operation.common.ResMessage resU=null;
			try {
				logger.info("----#---------#--更新merinf表信息，请求参数：--#---------#--" + req);
				resU=merInfoService.updateMerInfoAndMerExInfo(reqU);
				logger.info("----#---------#--更新merinf表信息，返回参数：--#---------#--" + res);
			} catch (Exception e) {
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "服务器异常，请稍后再试");
				logger.error("----#---------#--更新店铺信息异常--#---------#--" + e);
				return resultJson;
			}
			if(!"0000".equals(resU.getRetCode())){
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "修改失败");
				return resultJson;
			}
		}
		resultJson.put("retCode", "0000");
		resultJson.put("retMsg", "成功");
		return resultJson;
	}
	/**
	 *  变更为‘待复查’插入操作记录
	 * @param storeInf	店铺详情
	 * @param res	 
	 * @return
	 */
	public com.umpay.operation.common.ResMessage addJoinFlowForCheckMer(StoreInf storeInf){
		
		com.umpay.operation.common.ResMessage res = null;
		com.umpay.operation.common.ReqMessage req = ReqMessageUtil.makeOpReq();
		try {
			
		req.put(CommonConsts.MERUNIFORMID,storeInf.getStoreId());	//商户唯一标识
		req.put("handleState","0");	//申请处理状态
		req.put("handleState","0");	//申请处理状态   0-初始 1-完成
		req.put("handleStep","待复查");	//处理节点  中文描述
		req.put("handleRole","00");	//处理人角色：00系统自动；01财务； 02运营； 03客服 ；04商户 ；99其他		
		logger.info("----#---------#--变更为‘待复查’插入操作记录，请求参数：--#---------#--" + req);
		res = joinFlowServiceRemote.add(req);
		logger.info("----#---------#--变更为‘待复查’插入操作记录，返回参数：--#---------#--" + res);
		} catch (Exception e) {
			logger.error(storeInf.getStoreId() +"----#---------#--变更为‘待复查’插入操作记录异常--#---------#--" , e);		
		}
		return res;
	}
	/**
	 *  变更为‘已删除’插入操作记录
	 * @param storeInf	店铺详情
	 * @param res	 
	 * @return
	 */
	public com.umpay.operation.common.ResMessage addJoinFlowFordelMer(StoreInf storeInf){
		
		com.umpay.operation.common.ResMessage res = null;
		com.umpay.operation.common.ReqMessage req = ReqMessageUtil.makeOpReq();
		try {
			
		req.put(CommonConsts.MERUNIFORMID,storeInf.getStoreId());	//商户唯一标识
		req.put("handleState","0");	//申请处理状态   0-初始 1-完成
		req.put("handleStep","已删除");	//处理节点  中文描述
		req.put("handleRole","00");	//处理人角色：00系统自动；01财务； 02运营； 03客服 ；04商户 ；99其他
		req.put("handleUser",storeInf.getAgentId()+"_"+storeInf.getSalesmanId());	//处理人
		logger.info("----#---------#--变更为‘已删除’插入操作记录，请求参数：--#---------#--" + req);
		res = joinFlowServiceRemote.add(req);
		logger.info("----#---------#--变更为‘已删除’插入操作记录，返回参数：--#---------#--" + res);
		} catch (Exception e) {
			logger.error(storeInf.getStoreId() +"----#---------#--变更为‘已删除’插入操作记录异常--#---------#--" , e);		
		}
		return res;
	}
	/**
	 * 自助部署列表
	 * @author ChenFuLong 2017-05-16
	 * @param session
	 * @param request
	 * @param response
	 * @return
	 * @throws Exception
	 */
	@RequestMapping(value="/delStorInfo", produces="application/json;charset=UTF-8")
	@ResponseBody
	@SuppressWarnings("unchecked")
	public JSONObject delStorInfo(HttpSession session,HttpServletRequest request, HttpServletResponse response) throws Exception{
		logger.info("----#---------#---删除，开始--#---------#--");
		JSONObject resultJson = new JSONObject();
		String reqJSON = (String) request.getAttribute("_requestData");
		JSONObject json = null;
		try {
			json = JSONObject.fromObject(reqJSON);
		} catch (Exception e) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "请求参数不足");
			logger.error("----#---------#----删除数据转换异常--#---------#--" + e);
			return resultJson;
		}
		String storeId = (String) json.get("storeId");	//商户编号
	   
		
		//删除商户
		/**
		 * 通过店铺编号获取店铺详情
		 */
 		ReqMessage req = ReqMessageUtil.makeSpReq();
		ResMessage res = null;
		req.put("storeId", storeId);
		try {
			logger.info("----#---------#--根据店铺编号查询店铺详情，请求参数：--#---------#--" + req);
			res = storeInfServiceRemote.getStoreInfByPri(req);
			logger.info("----#---------#--根据店铺编号查询店铺详情，返回参数：--#---------#--" + res);
		} catch (Exception e) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "服务器异常，请稍后再试");
			logger.error("----#---------#--根据店铺编号查询店铺详情异常--#---------#--" + e);
			return resultJson;
		}
		if(!"0000".equals(res.getRetCode())){	//查询店铺详情失败或异常
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "服务器异常，请稍后再试");
			return resultJson;
		}else if(res.getResMap().get("storeInf") == null){	//未获取到店铺信息，storeId不存在
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "获取店铺信息失败");
			return resultJson;
		}
		
		StoreInf storeInf = (StoreInf) res.getResMap().get("storeInf");
		//~~~~~~~~~~~~~~~~~~~~~~查询该收款人下所有店铺~~~~~~~~~~~~~~~~~~~~~~~~~~~~
		
		ReqMessage req1 = ReqMessageUtil.makeSpReq();
		ResMessage res1 = null;				
		req1.put("merId",storeInf.getMerId());
		//req1.put("isDel","0");
		try {
			logger.info("----#---------#--获取自助部署列表，请求参数：--#---------#--" + req1);
			res1 = storeInfServiceRemote.getStoreInfList(req1);
			logger.info("----#---------#--获取自助部署列表，返回参数：--#---------#--" + res1);
		} catch (Exception e) {
			resultJson.put("retCode", "0001");
			resultJson.put("retMsg", "服务器异常，请稍后再试");
			logger.error("----#---------#--获取自助部署列表异常--#---------#--" + e);
			return resultJson;
		}
		if ("0000".equals(res1.getRetCode())) {
			List<StoreInf> storeInfs = (List<StoreInf>) res1.getResMap().get("storeInfList");
			Integer totalSize = (Integer) res1.getResMap().get("totalSize");
			
			StoreInf delStoreInf  = null;
			for(StoreInf storeDef : storeInfs){
				if(storeId.equals(StringUtil.trim(storeDef.getStoreId()))){
					delStoreInf = storeDef;
					break;
				}
			}
			String defultStore = delStoreInf.getDefultStore();
			//1.删除店铺
			if(del(delStoreInf)){
				logger.info("删除店铺成功！" + storeId);
			}else{
				logger.info("删除店铺失败：" + storeId);
				resultJson.put("retCode", "0001");
				resultJson.put("retMsg", "店铺更新失败");
				return resultJson;
			}
			//2.当前店铺为默认店铺且有多家店铺时，更新新的默认店铺
			if("0".equals(defultStore) && totalSize > 1){
				logger.info("删除店铺为默认店铺并且店铺>1,需要重新赋值一家店铺为默认店铺");
				StoreInf newStoreDef = null;
				StoreInf newStoreDef8 = null;
				StoreInf newStoreDef7 = null;
				StoreInf newStoreDef9 = null;
				StoreInf newStoreDef6 = null;
				StoreInf newStoreDef10 = null;
				for(StoreInf storeDef : storeInfs){
					if(storeId.equals(StringUtil.trim(storeDef.getStoreId()))){
						continue;
					}
					String state = StringUtil.trim(storeDef.getRegisterProcsState());
					newStoreDef = storeDef;
					if("08".equals(state)){
						newStoreDef8 = storeDef;
					}else if("07".equals(state)){
						newStoreDef7 = storeDef;				
					}else if("09".equals(state)){
						newStoreDef9 = storeDef;
					}else if("06".equals(state)){
						newStoreDef6 = storeDef;
					}else if("10".equals(state)){
						newStoreDef10 = storeDef;
					}
				}
				if(newStoreDef8 != null){
					newStoreDef = newStoreDef8;
				}else if(newStoreDef7 != null){
					newStoreDef = newStoreDef7;				
				}else if(newStoreDef9 != null){
					newStoreDef = newStoreDef9;
				}else if(newStoreDef6 != null){
					newStoreDef = newStoreDef6;
				}else if(newStoreDef10 != null){
					newStoreDef = newStoreDef10;
				}
				//~~~~~~~~~~~~~~~~~~~~~~~~~~修改默认店铺~~~~~~~~~~~~~~~~~~~~~~~~~~~
				newStoreDef.setDefultStore("0");
				ReqMessage req3 = ReqMessageUtil.makeSpReq();
				ResMessage res3 = null;	
				Map<String, String> storeMap = SaasPropertyUtil.javaBeanToMap(newStoreDef);
				req3.putAll(storeMap);
				try {
					logger.info("----#---------#--修改默认店铺，请求参数：--#---------#--" + req3);
					res3 = storeInfServiceRemote.updateStoreInf(req3);
					logger.info("----#---------#--修改默认店铺，返回参数：--#---------#--" + res3);
				} catch (Exception e) {
					resultJson.put("retCode", "0001");
					resultJson.put("retMsg", "服务器异常，请稍后再试");
					logger.error("----#---------#--修改默认店铺信息异常--#---------#--" + e);
					return resultJson;
				}
				if(!"0000".equals(res3.getRetCode())){
					resultJson.put("retCode", "0001");
					resultJson.put("retMsg", "修改默认店铺失败");
					return resultJson;
				}
													
			}		
			
			
		}
		resultJson.put("retCode", "0000");
		resultJson.put("retMsg", "成功");
		return resultJson;
	}
	
	/**
	 * 删除店铺子方法
	 * @param merchant
	 * @return
	 */
	public boolean del(StoreInf storeInf){	 
		try {

			
			//关闭产品
			//配置文件读取子商户对应产品号
			String storeIdProductId = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties","storeId.bProductId");
			String stateDel = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties","storeId.bProductId.state");
			String url = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties","cancelUrlStr");
			logger.info("配置文件参数:"+storeIdProductId);
			logger.info("配置文件参数:"+stateDel);
			logger.info("配置文件参数:"+url);
			String[] productIds = storeIdProductId.split("&");
	 		for(String productId:productIds){
				logger.info("注销产品关系，开始的产品号是:"+productId);
				//~~~~~~~~~~~~~~~~~~~~~根据主键查询商户商品关系接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
				com.umpay.operation.common.ReqMessage reqOp = ReqMessageUtil.makeOpReq();
				reqOp.put("merId",storeInf.getStoreId());
				reqOp.put("productId",productId);
				logger.info("【根据主键查询商户商品关系接口】入参："+ reqOp);
				com.umpay.operation.common.ResMessage resOp = merProductServiceRemote.getMerProductByKey(reqOp);
				logger.info("【根据主键查询商户商品关系接口】出参："+ resOp);
				if( !RetCode.SUCCESS.equals(resOp.getRetCode())){
					logger.info("根据主键查询商户商品关系接口调用失败：");
//					return ERROR;
				}
				MerProduct merProduct = (com.umpay.operation.model.product.MerProduct) resOp.getResMap().get("merProduct");
				if(merProduct != null){
					//~~~~~~~~~~~~~~~~~~~~~注销产品关系接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~
					logger.info("商户已开通此产品:" + productId );
					String cancelUrlStr = url + "UnRegMerAccount/"+ "MerProductStateCancel.xml";
					logger.info("注销产品关系请求url：" + url);
					Map<String,Object> reqMap=new HashMap<String,Object>();
					String rpidCrm = "sPweb" + SerialUtil.getRpid("merRpid", 10);
					reqMap.put("rpid", rpidCrm);
					reqMap.put("merId",storeInf.getStoreId());
					reqMap.put("productId",productId);
					logger.info("【注销产品关系接口】入参："+ reqMap);
					XStream xstream = new XStream(new DomDriver());
			        Map<String,Object> crmresMap= (Map<String, Object>) com.umfwechat.util.HttpUtil.getResObjPost(cancelUrlStr, xstream, reqMap);
			       	 
//			        Map<String,Object> crmresMap=(Map<String, Object>)HttpUtils.httpPostForm2Xml(cancelUrlStr, reqMap);
			        logger.info("【注销产品关系接口】出参："+ crmresMap);
			        if (!("0000".equals(StringUtil.trim(crmresMap.get("retCode")))) && !"00060403".equals(StringUtil.trim(crmresMap.get("retCode")))) {
			        	logger.info("通过crm注销产品关系失败");
//						return ERROR;
			        }
			        if( "00060403".equals(StringUtil.trim(crmresMap.get("retCode")))){
			        	logger.info("用户本处于注销状态");
			        }
			        logger.info("注销商户产品关系成功storeId:" + storeInf.getStoreId()+ "productId：" + productId);
				  
				}
				if(merProduct == null){
					logger.info("商户未开通此产品storeId：" + storeInf.getStoreId() + "productId:" + productId);
				}
			}
			//~~~~~~~~~~~~~~~~~~~~~修改店铺信息接口~~~~~~~~~~~~~~~~~~~~~~~~~~~
	 		
	 		ReqMessage req3 = ReqMessageUtil.makeSpReq();
			ResMessage res3 = null;	
			storeInf.setIsDel("1");
			logger.info("变更为‘已删除’插入操作记录 ------");	
			addJoinFlowFordelMer(storeInf);
			Map<String, String> storeMap = SaasPropertyUtil.javaBeanToMap(storeInf);
			req3.putAll(storeMap);
			try {
				logger.info("----#---------#--修改店铺信息接口，请求参数：--#---------#--" + req3);
				res3 = storeInfServiceRemote.updateStoreInf(req3);
				logger.info("----#---------#--修改店铺信息接口，返回参数：--#---------#--" + res3);
			} catch (Exception e) {
				 
				logger.error("----#---------#--修改店铺信息接口异常--#---------#--" + e);
				return false;
			}
			if(!"0000".equals(res3.getRetCode())){			 
				return false;
			}
	 		
	 		
			return true;
		} catch (Exception e) {
			logger.info("删除店铺失败！",e);
			return false;
		}
	}
	/**
	 * 查询pos机自护照部署列表
	 * @param agentId
	 * @param userId
	 * @param posState
	 * @return
	 */
	public JSONObject queryPosList(String agentId ,String userId ,String posState ,String pageSize,String pageNo ){
		logger.info("【查询pos机自助部署列表接口】开始");
		JSONObject resultJSON = new JSONObject();
		try {
			if(StringUtil.isEmpty(userId)|| StringUtil.isEmpty(agentId)||StringUtil.isEmpty(pageSize) || StringUtil.isEmpty(pageNo)){
				resultJSON.put(CommonConsts.RETCODE, com.umfwechat.common.code.RetCode.FAIL);
				resultJSON.put(CommonConsts.RETMSG, "请求参数不足");
				return resultJSON;
			}
			//缓存中取出password、assitid
			String str = RedisUtil.get(CacheConsts.LOGIN+agentId+userId);
			if(StringUtil.isEmpty(str)){
				logger.info("redis取数据为空！key：" + CacheConsts.LOGIN+agentId+userId);
				resultJSON.put(CommonConsts.RETCODE, com.umfwechat.common.code.RetCode.FAIL);
				resultJSON.put(CommonConsts.RETMSG, "redis中获取数据为空！");
				return resultJSON;
			}
			String[] values = str.split(",");
			String password = values[2];//缓存中的密码是明文需要加密
			String assitid = values[1];
			String passwordJM ;
			passwordJM = MessageDigestUtil.digest(password);//加密密码
			//判断agentId为几级代理商
			String currntChk = null;
			if(agentId.contains("Y")){
				logger.info("代理商为一级代理商：" + agentId);
				currntChk = "0";
			}else if(agentId.contains("E")){
				logger.info("代理商为二级代理商：" + agentId);
				currntChk="1";
			}else if(agentId.contains("S")){
				logger.info("代理商为三级代理商：" + agentId);
				currntChk="3";
			}
			//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~商户进件信息分页查询接口~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			String url = PropertyUtil.getStrValue("umfWeChatPlat_appConf.properties", "queryPosListURL");
			logger.info("商户进件查询分页接口请求url：" + url);
			Map<String,Object> params = new HashMap<String,Object>();
			com.umfwechat.common.ReqMessage req  = ReqMessageUtil.makeReq();
			params.put(CommonConsts.RPID, req.getRpid());
			params.put(CommonConsts.REQDATE, req.getReqDate());
			params.put(CommonConsts.REQTIME, req.getReqTime());
			params.put(CommonConsts.REQTIME, req.getReqTime());
			params.put(CommonConsts.USER_ID,userId);
			params.put(CommonConsts.ASSIST_ID,assitid);
			params.put(CommonConsts.PASS_WORD,passwordJM);
			params.put(CommonConsts.CURRNTCHK, currntChk);
			params.put(CommonConsts.DATASOURCE, "SAAS");
			params.put(CommonConsts.AGENTID, agentId);
			params.put(CommonConsts.PAGE_NUM, pageNo);
			params.put(CommonConsts.PAGE_SIZE, pageSize);
			if(StringUtil.isNotEmpty(posState) && !ValueConsts.ALL.equals(posState)){
				logger.info("查询pos机商户状态为：" + posState);
				params.put("agentcheckState", posState);
			}
			logger.info("【商户进件分页查询接口】入参：" + params);
			Map<String, Object> resultMap = HttpUtil.httpPostForm2Xml(url, params);
			logger.info("【商户进件分页查询接口】出参：" + resultMap);
			if( !com.umfwechat.common.code.RetCode.SUCCESS.equals(resultMap.get(CommonConsts.RETCODE))){
				logger.info("查询商户进件分页查询接口失败！");
				resultJSON.put(CommonConsts.RETCODE, com.umfwechat.common.code.RetCode.FAIL);
				resultJSON.put(CommonConsts.RETMSG, "查询商户进件分页接口失败！");
				return resultJSON;
			}
			String list1 =(String) resultMap.get(CommonConsts.LIST);
			List<Map<String, Object>> resultList = new ArrayList<Map<String,Object>>();
			if(StringUtil.isEmpty(list1)){
				logger.info("查询pos进件列表为空");
				resultJSON.put(CommonConsts.RETCODE, com.umfwechat.common.code.RetCode.SUCCESS);
				resultJSON.put(CommonConsts.RETMSG, "查询POS机自助部署列表无数据！");
				resultJSON.put(CommonConsts.STORE_LIST,resultList);
				return resultJSON;
			}
			List<Map<String, String>> list = new Gson().fromJson(list1, new TypeToken<List<Map<String, String>>>(){}.getType());
			for(int i = 0;i<list.size();i++){
				Map<String, Object> newMap = new HashMap<String,Object>();
				String updateTime = list.get(i).get(CommonConsts.UPDATETIME);
				if( StringUtil.isNotEmpty(updateTime)){
					SimpleDateFormat sdf = new SimpleDateFormat(ValueConsts.TIME);
					Date date  = sdf.parse(updateTime);
					updateTime = sdf.format(date);
//					updateTime = updateTime.substring(0, 19);
					newMap.put(CommonConsts.UPDATETIME, updateTime);
				}else {
					newMap.put(CommonConsts.UPDATETIME, "");
				}
				if(StringUtil.isNotEmpty(list.get(i).get(CommonConsts.LINKMAN))){
					newMap.put(CommonConsts.LINKMAN, list.get(i).get(CommonConsts.LINKMAN));
				}else {
					newMap.put(CommonConsts.LINKMAN, "");
				}
				if(StringUtil.isNotEmpty(list.get(i).get(CommonConsts.MERNAMESM))){
					newMap.put(CommonConsts.MERNAMESM, list.get(i).get(CommonConsts.MERNAMESM));
				}else {
					newMap.put(CommonConsts.MERNAMESM, "");
				}
				if(StringUtil.isNotEmpty(list.get(i).get(CommonConsts.ISREJECT))){
					newMap.put(CommonConsts.ISREJECT, list.get(i).get(CommonConsts.ISREJECT));
				}else {
					newMap.put(CommonConsts.ISREJECT, "");
				}
				if(StringUtil.isNotEmpty(list.get(i).get(CommonConsts.MERID))){
					newMap.put(CommonConsts.MERID, list.get(i).get(CommonConsts.MERID));
				}else {
					newMap.put(CommonConsts.MERID, "");
				}
				if(StringUtil.isNotEmpty(list.get(i).get(CommonConsts.MOBILEID))){
					newMap.put(CommonConsts.MOBILEID, list.get(i).get(CommonConsts.MOBILEID));
				}else {
					newMap.put(CommonConsts.MOBILEID, "");
				}
				if(StringUtil.isNotEmpty(list.get(i).get(CommonConsts.AGENTCHECKSTATE1))){
					newMap.put(CommonConsts.AGENTCHECKSTATE1, list.get(i).get(CommonConsts.AGENTCHECKSTATE1));
				}else {
					newMap.put(CommonConsts.AGENTCHECKSTATE1, "");
				}
				resultList.add(newMap);
			}
			resultJSON.put(CommonConsts.RETCODE, com.umfwechat.common.code.RetCode.SUCCESS);
			resultJSON.put(CommonConsts.RETMSG, "查询pos机商户列表成功！");
			if( null != list && 0 < list.size()){
				resultJSON.put(CommonConsts.STORE_LIST,resultList);
			}else{
				resultJSON.put(CommonConsts.STORE_LIST,resultList);
			}
			return resultJSON ;
		} catch (Exception e) {
			logger.error("查询POS机自助部署列表异常",e);
			resultJSON.put(CommonConsts.RETCODE, com.umfwechat.common.code.RetCode.FAIL);
			resultJSON.put(CommonConsts.RETMSG, "查询POS机自助部署列表失败！");
			return resultJSON;
		}
	}
}
